﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
public partial class admin_Site_Add_site_AddNew : System.Web.UI.Page
{
    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;
    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();

    /// <summary>
    /// 显示下拉菜单的表
    /// </summary>
    DataTable NewDt = new DataTable();

    /// <summary>
    /// sql语言
    /// </summary>
    string sql = "";

    string Rid = "";

    /// <summary>
    /// 站点常用 方法 
    /// </summary>
    public Tong.ThisSiteUse.SiteTong TextThisSite = new Tong.ThisSiteUse.SiteTong();
    protected void Page_Load(object sender, EventArgs e)
    {

        Button2.Attributes.Add("onclick", "window.open('../../inc/UpFile.aspx?formname=aspnetForm&amp;editname=" + CX_Column_Pic.ClientID.ToString() + "&amp;uppath=UpFile','','status=no,scrollbars=no,top=20,left=110,width=600,height=265')");
        if (!IsPostBack)
        {
            BindData();
        }
        
    }

    int ii = 0;
    /// <summary>
    /// 返回菜单显示的HTML代码
    /// </summary>
    /// <param name="select">显示的展次</param>
    /// <returns></returns>
    public void ShowTree(int select)
    {
        string sql;
        int i = 0;
        DataTable MyDt = new DataTable();
        sql = "Select * From ask_Column where CX_Column_LX <> 3 and CX_Column_followid =" + select + " order by CX_Column_id desc";
        try
        {

            MyDt = TextData.SqlataSet(sql).Tables[0];//创建DataTable MyDt
        }
        catch (Exception ex)
        {
            //TextData.Err(ex.Message);

        }
        for (i = 0; i < MyDt.Rows.Count; i++)//遁环记录集
        {
            if (select == 0)//如果只一有层的话
            {

                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            else
            {
                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            ii = ii + 1;
            ShowTree(int.Parse(MyDt.Rows[i]["CX_Column_id"].ToString()));//调用自己显示菜单ＨＴＭＬ
            ii -= 1;

        }


    }

    void BindData()
    {
        DataRow Row = NewDt.NewRow();
        NewDt.Columns.Add("东东");
        NewDt.Columns.Add("Conts");
        Row[0] = "0";//一级爱问分类
        Row[1] = "一级爱问分类";
        NewDt.Rows.Add(Row);
        ShowTree(0);
        try
        {
            Rid = int.Parse(Request.QueryString["id"].ToString().Trim()).ToString();
            CX_Column_Class.DataSource = NewDt.DefaultView;
            CX_Column_Class.DataTextField = "Conts";
            CX_Column_Class.DataValueField = "东东";
            CX_Column_Class.SelectedValue = Rid;
            CX_Column_Class. DataBind();


        }
        catch
        {
            CX_Column_Class.DataSource = NewDt.DefaultView;
            CX_Column_Class.DataTextField = "Conts";
            CX_Column_Class.DataValueField = "东东";
            CX_Column_Class.SelectedValue = "0";
            CX_Column_Class.DataBind();
        }
    }

    /// <summary>
    /// 页面保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {

        try
        {
            int.Parse(CX_Column_Sort.Text.Trim());
        }
        catch
        {
            tt.Text = "输入排序不能转换";
            Response.End();
        }

        //爱问分类类型 查看爱问分类类型 1 为新闻爱问分类 , 
        string CX_Column_LX = "0"; //爱问分类类型 墨认为0 一般爱问分类
        if (Radio0.Checked == true) //Radio0 一般爱问分类
        {
            CX_Column_LX = "0";
        }
        if (Radio1.Checked == true)//Radio1 为新闻爱问分类 , 
        {
            CX_Column_LX = "1";
        }

        if (Radio2.Checked == true)//Radio2 为其它爱问分类 , 
        {
            CX_Column_LX = "2";
        }

        if (Radio3.Checked == true)//Radio3 为系统爱问分类 , 
        {
            CX_Column_LX = "3";
        }

        if (CX_Column_Name.Text.Trim() != "" && CX_Column_Directory.Text.Trim() != "" && CX_Column_ItemTemplate_Url.Text.Trim() != "" )
        {


            sql = "insert into [ask_Column] ( CX_Column_followid,  CX_Column_Name,  CX_Column_Class,  CX_Column_Directory,  CX_Column_Explair,   CX_Column_ItemTemplate_Url,  CX_Column_ItemTeplate_Parame, CX_Column_Sort,CX_Column_LX,CX_Column_Pic )";
            sql = sql + "values(";
            sql = sql + " " + CX_Column_Class.SelectedValue + ",'" + CX_Column_Name.Text.Trim() + "','" + CX_Column_Class.Text.Trim() + "', '" + CX_Column_Directory.Text.Trim() + "','" + CX_Column_Explair.Text.Trim() + "', '" + CX_Column_ItemTemplate_Url.Text.Trim() + "', '" + CX_Column_ItemTeplate_Parame.Text.Trim() + "'," + CX_Column_Sort.Text.Trim() + "," + CX_Column_LX + ",'" + CX_Column_Pic.Text.Trim().Replace("'","") + "')";
            //如果没有这个表的话



                    TextData.SqlDataSave(sql);//保存数据

                    tt.Text = "添加爱问分类 " + CX_Column_Name.Text.Trim() + "成功";
                    CX_Column_Name.Text = "";
                    CX_Column_Directory.Text = "";
                    BindData();
              



        }
        else
        {
            tt.Text = "输入的信息内容不正确";
        }
        //Response.Write(sql);


    }



}
